import { deepCopy } from "@/package/treeMethods/copy.ts";
import echarts from "echarts";

export default {
  install(app: any, options: any) {
    app.config.globalProperties = {
      ...app.config.globalProperties,
      name: "veloma",
      loveEating: "山竹",
      // 深拷贝(复杂)
      v_copy: deepCopy,
      // 深拷贝(简单)
      v_simple_copy(data: any) {
        try {
          return JSON.parse(JSON.stringify(data));
        } catch (error) {
          console.log("报错了", error);
          return data;
        }
      },
      // 轮询
      dataDriven(callback: () => boolean | Promise<any>, time: number) {
        const timer = setInterval(async () => {
          let flag = callback();
          flag = (flag instanceof Promise) ? await flag : flag;
          if (flag) {
            clearInterval(timer);
          }
        }, (time || 100));
      },
      $echarts: echarts
    }
  }
}